package com.baiytfp.hf.HFDataExchange.common.base;

import org.apache.shiro.session.Session;
import org.apache.shiro.session.SessionListener;
import org.apache.shiro.session.SessionListenerAdapter;

import com.baiytfp.hf.HFDataExchange.common.model.table.User_info;
import com.baiytfp.hf.baiytfp.hfutils.HFLog;

public class UserSessionListener extends SessionListenerAdapter {

	 /**
     * Adapter no-op implemenation - does nothing and returns immediately.
     *
     * @param session the session that has started.
     */
    public void onStart(Session session) {
        //no-op
    }

    /**
     * Adapter no-op implemenation - does nothing and returns immediately.
     *
     * @param session the session that has stopped.
     */
    public void onStop(Session session) {
    	doLogoutEvent(session);
    }

    /**
     * Adapter no-op implemenation - does nothing and returns immediately.
     *
     * @param session the session that has expired.
     */
    public void onExpiration(Session session) {
    	doLogoutEvent(session);
    }
    
    
    private void doLogoutEvent(Session session) {
    	User_info vo = (User_info) session.getAttribute("userVO");
    	if(vo != null ) {
    		new HFLog(HFLog.TYPE_LOGOUT).logoutToDB(vo.getUser_code(), vo.getUser_name());
    	}
    }
}
